package com.deep.transaction.demo7.service;

import com.deep.transaction.demo7.dao.UserDao;
import com.deep.transaction.demo7.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


@Service
public class UserService2 {
    @Autowired
    private UserDao userDao;

    @Transactional
    public void testNotPublic(User user) {
        userDao.insert(user);
        int i = 1 / 0;
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void testRequired(User user) {
        userDao.insert(user);
        int i = 1 / 0;
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    public void testSupports(User user) {
        userDao.insert(user);
        int i = 1 / 0;
    }

    @Transactional(propagation = Propagation.MANDATORY)
    public void testMandatory(User user) {
        userDao.insert(user);
        int i = 1 / 0;
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void testRequiresNew(User user) {
        userDao.insert(user);
//        int i = 1/0;
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void testNotSupported(User user) {
        userDao.insert(user);
//        int i = 1/0;
    }

    @Transactional(propagation = Propagation.NEVER)
    public void testNever(User user) {
        userDao.insert(user);
//        int i = 1/0;
    }

    @Transactional(propagation = Propagation.NESTED)
    public void testNested(User user) {
        userDao.insert(user);
        int i = 1 / 0;
    }
}
